package com.xiaoma.h5testdemo.business.main.vm

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.xiaoma.common.extend.toLiveData
import com.xiaoma.common.utils.VmEvent
import com.xiaoma.h5testdemo.business.main.utils.XmFragmentStackManager
import com.xiaoma.lib.log.KLog

/**
 * author: liangjingbo
 * date: 2024/4/18
 * describe:
 */
class HostActVm : ViewModel() {

    private val _actionFullScreen = MutableLiveData<VmEvent<Boolean>>()
    val actionFullScreen = _actionFullScreen.toLiveData()

    private val _actionHiddenNavigationBar = MutableLiveData<VmEvent<Boolean>>()
    val actionHiddenNavigationBar = _actionHiddenNavigationBar.toLiveData()

    private val _actionJumpWeb = MutableLiveData<VmEvent<String>>()
    val actionJumpWeb = _actionJumpWeb.toLiveData()

    private val _actionGoToHome = MutableLiveData<VmEvent<String>>()
    val actionGoToHome = _actionGoToHome.toLiveData()

    var mXmFragmentStackManager: XmFragmentStackManager? = null

    fun enterFullScreen() {
        KLog.i(TAG, "enterFullScreen() ")
        _actionFullScreen.value = VmEvent.data(true)
    }

    fun exitFullScreen() {
        KLog.i(TAG, "exitFullScreen() ")
        _actionFullScreen.value = VmEvent.data(false)
    }

    fun hiddenNavigationBar() {
        KLog.i(TAG, "hiddenNavigationBar() ")
        _actionHiddenNavigationBar.value = VmEvent.data(true)
    }

    fun cancelHiddenNavigationBar() {
        KLog.i(TAG, "cancelHiddenNavigationBar() ")
        _actionHiddenNavigationBar.value = VmEvent.data(false)
    }

    fun handleJumpWeb(url: String) {
        KLog.i(TAG, "handleJumpWeb() url:$url")
        _actionJumpWeb.postValue(VmEvent.data(url))
    }

    fun goToHome() {
        _actionGoToHome.postValue(VmEvent.event())
    }

    companion object {
        private val TAG = HostActVm::class.java.simpleName + "_XMTag"
        private const val MAIN_TAG_PREFIX = "main_tag_prefix_"
        private const val WEB_TAG_PREFIX = "web_tag_prefix_"

    }
}